package com.service.atf.base.type;

import com.service.atf.base.core.GlobalDefine;
import com.service.atf.base.exception.TFException;
import com.service.atf.base.utils.ATFConstants;

import java.io.IOException;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;

/**
 * User: luotao
 * Date: 12-2-25
 * Time: 12:57
 */
public class BuffReaderHead {
    MappedByteBuffer buffer;

    public BuffReaderHead(FileChannel fileChannel, int position) {
        try {
            this.buffer = fileChannel.map(FileChannel.MapMode.READ_WRITE, position * GlobalDefine.TF_HEAD_LEN_EVERY
                    , GlobalDefine.TF_HEAD_LEN_EVERY);
        } catch (IOException e) {
            throw new TFException(ATFConstants.ATF_TF_CRETE_HEADER_ERR, "����ͷ��ӳ�����");
        }
    }

    public int read() {
        buffer.position(0);
        return buffer.getInt();
    }
}
